<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="layout/login">
<head>
    <title>登录应用系统</title>
    <section layout:fragment="head">
        <script type="text/javascript">
            var contextPath = '[[${#httpServletRequest.contextPath}]]';
            var postUrl = '[[${postUrl}]]';

            function auth2() {
                $.post(postUrl, $('#loginForm').serialize(),
                    function (data, textStatus) {
                        if (data.result) {
                            document.location.reload();
                        } else {
                            $(".message").html(data.message);
                            alert(data.message);
                        }
                    }, "json");
            }
        </script>
    </section>

</head>
<body layout:fragment="body">
<div class="login-box animated fadeInDown">
    <div class="login-logo" style="width:120px;font-size:29px;margin:0px auto;"><strong>应用</strong>系统</div>
    <div class="login-body">
        <div class="login-title"><strong>登录</strong>你的账号</div>

        <form id="loginForm" th:action="${postUrl}" class="form-horizontal" method="post" autocomplete='off'>

            <div class="form-group">
                <div class="col-md-12">
                    <div class='message' style="color: #ff0000;" th:text="${message}"></div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <input type="text" id="username" name="username" class="form-control" placeholder="用户名"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <input type="password" id="password" name="password" class="form-control" placeholder="密码"/>
                </div>
            </div>
            <div th:unless="${#httpServletRequest.getSession().getAttribute('captchaForLogin')==null}">
                <div class="form-group">
                    <div class="col-md-6">
                        <img th:src="${#httpServletRequest.contextPath}+'/simpleCaptcha/image'"/>
                    </div>
                    <div class="col-md-6">
                        <input type="text" name="captchaChallenge" class="form-control" placeholder="验证码"/>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-6">
                    <button type="submit" class="btn btn-info btn-block">登录</button>
                </div>
                <div class="col-md-6">
                    <button type="button" onclick="auth2()" class="btn btn-info btn-block">ajax登录</button>
                </div>
            </div>
        </form>
    </div>
    <div class="login-footer">
        <div class="pull-left">
            &copy; 2020 AppName
        </div>
        <div class="pull-right">
            <a th:href="${#httpServletRequest.getContextPath()}+'/register/index'">注册</a> |
            <a th:href="${#httpServletRequest.getContextPath()}+'/'">返回前台</a>
        </div>
    </div>
</div>
</body>
</html>